<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:mo="https://gitee.com/aun/Timo"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})">
</head>
<body class="timo-layout-page">
    <div class="layui-card">
        <div class="layui-card-header timo-card-header">
            <span><i class="fa fa-bars"></i> 版本管理</span>
            <i class="layui-icon layui-icon-refresh refresh-btn"></i>
        </div>
        <div class="layui-card-body">
            <div class="layui-row timo-card-screen">
                <div class="pull-left layui-form-pane timo-search-box">
                    <div class="layui-inline">
                        <label class="layui-form-label">版本名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="version" th:value="${param.version}" placeholder="请输入版本名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline" shiro:hasPermission="app:versionApp:allapps">
                        <label class="layui-form-label">产品线</label>
                        <div class="layui-input-block" th:with="prodLineId=${param.prodLineId}">
                            <div th:replace="/common/fragment :: selectTag('prodLineId',${prodLines},${prodLineId},'id','title','')"></div>
                        </div>
                    </div>
                    <div class="layui-inline" shiro:hasPermission="app:versionApp:allapps">
                        <label class="layui-form-label">参与人员</label>
                        <div class="layui-input-block" th:with="leaderId=${param.leader_id}">
                            <div th:replace="/common/fragment :: selectTag('leader_id',${users},${leaderId},'id','nickname','')"></div>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">需求概述</label>
                        <div class="layui-input-block">
                            <input type="text" name="demand_title" th:value="${param.demand_title}" placeholder="请输入需求概述" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">需求URL</label>
                        <div class="layui-input-block">
                            <input type="text" name="demand_url" th:value="${param.demand_url}" placeholder="请输入需求URL" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">发布分支</label>
                        <div class="layui-input-block">
                            <select class="timo-search-select layui-input" name="co_release_branch" th:style="${param.co_release_branch=='1'?'color:green':''}" mo:dict="APP_VERSION_CHECKOUT_STATUS" mo-selected="${param.co_release_branch}"></select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">发布状态</label>
                        <div class="layui-input-block">
                            <select class="timo-search-select layui-input" name="published" mo:dict="APP_VERSION_PUBLISHED" mo-selected="${param.published}"></select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn timo-search-btn">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>
                </div>
                <div class="pull-right screen-btn-group">
                    <button class="layui-btn open-popup" data-title="查询基线代码" th:attr="data-url='http://172.18.12.44:8002'" data-size="auto">
                        <i class="fa fa-search"></i> 查询基线代码</button>

                    <button class="layui-btn open-popup" data-title="查看并行开发应用" th:attr="data-url=@{/app/version/check/appcurrency}" data-size="auto">
                        <i class="fa fa-info-circle"></i> 查看并行开发应用</button>

                    <button class="layui-btn open-popup" data-title="添加版本管理" th:attr="data-url=@{/app/version/add}" data-size="auto">
                        <i class="fa fa-plus"></i> 添加</button>
                    <div class="btn-group" th:remove="all">
                        <button class="layui-btn">操作<span class="caret"></span></button>
                        <dl class="layui-nav-child layui-anim layui-anim-upbit">
                            <dd><a class="ajax-status" th:href="@{/app/version/status/ok}">启用</a></dd>
                            <dd><a class="ajax-status" th:href="@{/app/version/status/freezed}">冻结</a></dd>
                            <dd><a class="ajax-status" th:href="@{/app/version/status/delete}">删除</a></dd>
                        </dl>
                    </div>
                </div>
            </div>
            <div class="timo-table-wrap">
                <table class="layui-table timo-table">
                    <thead>
                    <tr>
                        <th>开发分支</th>
                        <th>涉及产品线</th>
                        <th>开发负责人</th>
                        <th>项目开始时间</th>
                        <th>任务类型</th>
                        <th>需求概述</th>
                        <th>需求URL</th>
                        <th>从prod合并</th>
                        <th>发布分支</th>
                        <th>发布状态</th>
                        <th>发布时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="item:${list}">
                        <td th:text="${item?.hotfix_flag=='1'?'hotfix':'dev'}+'-'+${item.version}">版本名称</td>
                        <td th:text="${#entity.getProductionTitles(item.id)}" style="white-space: pre-wrap;">涉及产品线</td>
                        <td th:title="开发负责人">
                            <div th:replace="/common/fragment :: selectTag('leader_id',${users},${item.leader_id},'id','nickname','disabled')"></div>
                        </td>
                        <td th:text="${#dates.format(item.start_time, 'yyyy-MM-dd')}">项目开始时间</td>
                        <td th:style="${'color:'+(item.hotfix_flag=='1'?'red':'green')}" th:text="${item.hotfix_flag=='1'?'缺陷修复':'正常需求'}">需求</td>
                        <td style="white-space: normal;"><pre th:text="${item.demand_title}">需求概述</pre></td>
                        <td th:text="${item.demand_url}" style="word-break: break-all; white-space: normal;">需求URL</td>
                        <td class="mergeProd2DevStatusTxt" th:attr="data-id=${item.id}">
                        </td>
                        <td>
                            <select class="timo-search-select layui-input" th:style="${item.co_release_branch=='1'?'color:green':''}" mo:dict="APP_VERSION_CHECKOUT_STATUS" mo-selected="${item.co_release_branch}" disabled="disabled"></select>
                        </td>
                        <td>
                            <select class="timo-search-select layui-input" th:style="${item.published=='1'?'color:green':''}" mo:dict="APP_VERSION_PUBLISHED" mo-selected="${item.published}" disabled="disabled"></select>
                        </td>
                        <td th:text="${item.published=='0'? '-': #dates.format(item.publishtime, 'yyyy-MM-dd HH:mm')}">上线时间</td>
                        <td>
                            <a th:if="${item.published=='0'}" class="open-popup" data-title="编辑版本管理" th:attr="data-url=@{'/app/version/edit/'+${item.id}}" data-size="auto" href="#">编辑</a>
                            <a class="open-popup" data-title="详细信息" th:attr="data-url=@{'/app/version/detail/'+${item.id}}" data-size="1100,800" href="#">详细</a>
                            <a th:if="${item.published=='0'}" class="ajax-get" data-msg="您是否确认删除" th:href="@{/app/version/status/delete(ids=${item.id})}">删除</a>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div th:replace="/common/fragment :: page"></div>
        </div>
    </div>
<script th:replace="/common/template :: script"></script>
<script type="text/javascript" th:src="@{/js/plugins/jquery-2.2.4.min.js}"></script>
<script type="text/javascript">
    layui.use(['laydate'],function () {
        var laydate = layui.laydate
        laydate.render({
            elem: '#startTime'
        });
    });
    $(document).ready(function () {
        $('.mergeProd2DevStatusTxt').each(function (item) {
            let thiz = $(this);
            $.get('/app/version/merge/result?versionId='+$(this).attr('data-id'),function (res) {
                if(res.code==200){
                    if(res.data){
                        thiz.html('<span style="color: red">有冲突</span>')
                    }else{
                        thiz.html('正常')
                    }
                }else{
                    thiz.html(res.msg)
                }
            });
        });
    });
</script>
</body>
</html>